import java.util.Scanner;

public class demo02 {
    //特别数的和
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n=sc.nextInt();
        long sum=0;
        for(int i=1;i<=n;i++){
            if(check(i)){
                sum+=i;
            }
        }
        System.out.println(sum);
        sc.close();
    }
    public static boolean check(int tmp){
        while(tmp!=0){
            if(tmp%10==2||tmp%10==0||tmp%10==1||tmp%10==9){
                return true;
            }
            tmp/=10;
        }
        return false;
    }
}
